<?php
declare (strict_types = 1);

namespace app\controller;

use app\BaseController;
use think\facade\Filesystem;
use think\Response;

class Upload extends BaseController
{
    /**
     * 显示资源列表
     *
     * @return Response
     */
    public function uploadFile(): Response
    {
        $file = $this->request->file('avatar');
        if (empty($file)) {
            return $this->error('请选择上传文件');
        }
        $savePath = Filesystem::disk('public')->putFileAs('avatar', $file, $file->getOriginalName());
        $data = [
            'url' => env('APP_HOST').'/storage/' . $savePath
        ];
        return $this->success('success', $data);
    }

}
